class MyBitmap {
  constructor(size) {
    this.size = size;
    this.words = new Array(this.getWordIndex(size - 1) + 1);
  }
  /**
   * 定位bitmap某一位所对应的word
   * @param bitIndex  位图的第bitIndex位
   */
  getWordIndex(bitIndex) {
    //右移6位，相当于除以64
    return bitIndex >> 6;
  }
  /**
   * 判断bitmap某一位的状态
   * @param bitIndex  位图的第bitIndex位
   */
  getBit(bitIndex) {
    if (bitIndex < 0 || bitIndex > this.size - 1) {
      throw new Error("超过bitmap有效范围");
    }
    let wordIndex = this.getWordIndex(bitIndex);
    return (this.words[wordIndex] & (1 << bitIndex)) != 0;
  }
  /**
   * 把bitmap某一位设为真
   * @param bitIndex  位图的第bitIndex位
   */
  setBit(bitIndex) {
    if (bitIndex < 0 || bitIndex > this.size - 1) {
      throw new Error("超过bitmap有效范围");
    }
    let wordIndex = this.getWordIndex(bitIndex);
    this.words[wordIndex] |= (1 << bitIndex);
  }
}
let bitMap = new MyBitmap(128);
bitMap.setBit(126);
bitMap.setBit(75);
console.log(bitMap.getBit(126));
console.log(bitMap.getBit(78));